package org.fengling.readingplatform.booklist.controller;

import io.swagger.v3.oas.annotations.Operation;
import org.fengling.readingplatform.booklist.service.BooklistService;
import org.fengling.readingplatform.model.entity.novel.NovelInfo;
import org.fengling.readingplatform.model.vo.common.Result;
import org.fengling.readingplatform.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/booklist")
public class BooklistController {

    @Autowired
    private BooklistService booklistService;

    @Operation(summary = "取消收藏")
    @DeleteMapping("auth/deleteNovel/{novelId}")
    public Result deleteNovel(@PathVariable("novelId") Long novelId){
        booklistService.deleteNovel(novelId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "添加进书单")
    @GetMapping(value = "/auth/addToBooklist/{novelId}")
    public Result addToBooklist(@PathVariable Long novelId){
        booklistService.addToBooklist(novelId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "查询书单")
    @GetMapping("/auth/getBooklist")
    public Result<List<NovelInfo>> getBooklist() {
        List<NovelInfo> novelInfoList = booklistService.getBooklist();
        return Result.build(novelInfoList, ResultCodeEnum.SUCCESS);
    }
}
